home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / tlx_sq15.zip / DNLOAD.SLT < prev    next >
Text File  |  1991-02-02  |  26KB  |  775 lines

  1. //-----------------------------------------------------------
  2. // DNLOAD.SL? Automatic download from BBS systems.
  3.  
  4. str dll_file [] = "DOWNLOAD";            // Download log file.
  5.  
  6. //-----------------------------------------------------------
  7. // The file <BBS>.DL must be placed in TELIX's program (main)
  8. // directory. <BBS> consists of the first 8 (max.) alphabetic
  9. // characters of the BBS name.
  10. // The following parameters must be defined in this file:
  11.  
  12. // Filename to download.
  13. // Filename to download
  14. // etc.
  15.  
  16. // Example:
  17.  
  18. // GAME1.ZIP
  19. // GAME2.ZIP
  20. // GRAPHICS.ZIP
  21.  
  22. // You may specify as many files as you want. However, the
  23. // script attempts to download only 10 files. The script does
  24. // not attempt to download files that are already in the download
  25. // directory. Thus you may run the script repeatedly to download
  26. // more files (if you have enough file time) without having to
  27. // modify the specification file manually.
  28.  
  29. // These files are downloaded to the directory defined for
  30. // this purpose in TELIX. You may NOT specify directory
  31. // (path) in the download specifications.
  32.  
  33. // If you have suggestions for generalizing this script
  34. // without making it too complicated, please upload your
  35. // new version to this BBS, or suggest improvements to me
  36. // via old-fashioned mail to:
  37.  
  38. //   Inge Vabekk
  39. //   Hamangskogen 108
  40. //   N-1300 SANDVIKA
  41. //   NORWAY                   
  42. //-----------------------------------------------------------
  43.  
  44. // Hint: Define a softkey to trigger this file (define in NAME.DAT)
  45.  
  46. str dls_file [14]            // Download specifications 
  47.    ,NextConf [14]            // Next conference
  48.    ,PrevConf [14]            // Previous conference
  49.    ,myprot    [2]            // "My" protocol
  50.    ,hisprot   [2]            // The BBS's protocol
  51.    ,shortname [8]            // Short name of BBS.
  52.    ,input    [80]            // Input line.
  53.    ,runstr   [80]            // Run string for DSZ.
  54.    ,f0       [14]            // Filename for download.
  55.    ,command  [10]            // Command prompt.
  56.    ,temp      [4]            // Temporary for short strings.
  57.    ,password [14]            // Password for file download.
  58.                              // For the Global storage:
  59.    ,global   []="GLOBAL"     // Global script.
  60.    ,bbstype  []="BTYPE"      // BBS type.
  61.    ,short    []="SHORT"      // Short BBS name.
  62.    ,Cprot    []="CPROT"      // Current protocol.
  63.    ,Hprot    []="HPROT"      // "His" protocol.
  64.    ,version  []="PCBVER"     // PCB version
  65.    ,conf     []="CONF"       // Current conference
  66.    ,prompt   []="PROMPT"     // Current command prompt.
  67.    ,maxdn    []="MAXDN"      // Max. files for download.
  68.    ,dsz      []="DSZ"        // DSZ parameters.
  69.    ,filist   []="FILIST"     // Name of the BBS file list
  70.    ,fpass    []="FPASS"      // Password for downloading.
  71.    ;     
  72.  
  73. // Other constants and variables.
  74.  
  75. int tol = 300      // timeout limit 30 sec.
  76.    ,tmark, stat
  77.    ,mbbs, pcb, rbbs, opus, fido, crcs    // Possible BBS types
  78.    ,PCBver         // PCBoard version.
  79.    ,infile         // Input file pointer
  80.    ,infilemenu     // TRUE if in file menu
  81.    ,success        // Count of succesful downloads.
  82.    ,fail = 0       // Number of failures.
  83.    ,MAX            // Max # files to download 
  84.    ,MORE           // More files to download 
  85.    ,switched       // TRUE (1) if conferences switched.
  86.    ,protocol       // Must be INT.
  87.    ,usedsz         // TRUE if using DSZ.
  88.    ;
  89.  
  90. //-----------------------------------------------------------
  91. // DNload script starts here.
  92. //-----------------------------------------------------------
  93.  
  94. main()
  95. {
  96. int c, i, k;               // Temporary storage.   
  97. int error;
  98.  
  99.   entry();                               // Updates colors & status bar. 
  100.  
  101. // Check if online.
  102. //-----------------------------------------------------------
  103.  
  104.   if (!carrier())   
  105.   { status_wind ("YOU CAN ONLY DOWNLOAD IF YOU'RE ONLINE!",20);
  106.     return (-1);
  107.   }
  108.   
  109. // Find BBS type (Set one logical variable).
  110.  
  111.   read (bbstype,input);                  // Get BBS type,
  112.   mbbs = pcb = rbbs = opus = fido = crcs = 0;
  113.   if      (input == "MBBS") mbbs = 1;
  114.   else if (input == "PCB" ) 
  115.   { pcb = 1;
  116.     read (version,temp);
  117.     PCBver = stoi (temp);                // PCB version.
  118.   }
  119.   else if (input == "RBBS") rbbs = 1;
  120.   else if (input == "OPUS") opus = 1;
  121.   else if (input == "FIDO") fido = 1;
  122.   else if (input == "CRCS") crcs = 1;
  123.   else                                          
  124.   { wrongBBS();                          // Doesn't match script!
  125.     return (-1);
  126.   }
  127.  
  128.   read (prompt,command);                 // Get command prompt.
  129.   read (cprot,myprot);                   // Protocol.
  130.   protocol = toupper(subchr(myprot,0));
  131.   read (hprot,hisprot);                  // His protocol.
  132.   if (pcb) NextConf = "Main Board";      // Join Main conference.
  133.   read (conf,PrevConf);                  // Get current conference.
  134.   switched = 0;
  135.  
  136.   read (short,shortname);                // Get the short name and build
  137.   dls_file = shortname;                  // name of download spec. file.
  138.   strcat (dls_file,".DL");               // Add extension.
  139.  
  140.   infile = filesize(dls_file);           // Check if download file exists.
  141.   if (infile < 0)                        // If not,
  142.   { run ("HAVEIT$",shortname,0);         // run program to build it.
  143.     infile = filesize(dls_file);         // Check result.
  144.   }
  145.   if (infile > 0)
  146.     infile = fopen (dls_file,"r");       // Open file for READ.
  147.  
  148.   if (infile <= 0) goto done;            // No file???
  149.  
  150.   read (maxdn,temp);
  151.   MAX = MORE = stoi (temp);              // More files to check:
  152.  
  153.   success = 0;                           // No files so far.
  154.   if (read (dsz,runstr) > 0              // Are we using DSZ?
  155.     && protocol == 'Z')
  156.   { strcat (runstr," rz -m");            // Add parameters.
  157.     usedsz = 1;
  158.   }
  159.  
  160.   infilemenu = 0;                        // NOT in file menu yet.
  161.   while ((error=fgets (input,80,infile)) > 0    // Download files.
  162.          && MORE && (success < MAX) 
  163.          && carrier())
  164.   { if (strlen(input) < 3)
  165.       break;                             // Line too short to make sense.
  166.     i = 0;
  167.     do
  168.     { for (k=0; (c=subchr(input,i))>='!'; ++i)
  169.       { c = toupper(c);
  170.         if (k==0)
  171.           if (c=='#' || c=='+' || c=='-' || c=='&')
  172.             continue;
  173.         setchr (f0,k,c);                 // ANY char. > space)
  174.         ++k;
  175.       }
  176.       ++i;
  177.       if (!c) break;                     // Break out at end of line.
  178.     } while (k < 2);                     // One char. is not enough!
  179.     setchr (f0,k,0);                     // End of string.
  180.  
  181.     for(i=0; (c=subchr(input,i))<=' '; ++i)
  182.       ;                                  // Find first character.
  183.  
  184.     if (c=='#' || c =='+' || c=='-')     // Change conference?
  185.     { substr (input,++i,14,NextConf);    // Copy conference name.
  186.       getfiles();                        // Get files in hold first.
  187.       setconf(c);                        // Set conference.
  188.     }
  189.     else if (c=='&')                     // Password?
  190.     { substr (input,++i,14,password);    // Copy password.
  191.       write (fpass,password);            // Update password.
  192.     }
  193.     else
  194.       if (k > 1) DL();                   // Download this file....
  195.   }
  196.   getfiles();                            // Get files in hold.
  197.   fclose (infile);                       // Close the command file. 
  198.  
  199. done:
  200.   fdelete (dls_file);
  201.   if (!carrier()) return (-1);
  202.   
  203.   return(0);
  204. }
  205.  
  206. //-----------------------------------------------------------
  207. // Get files in hold.
  208. //-----------------------------------------------------------
  209.  
  210. getfiles()
  211. {
  212. int i;
  213.   if (PCBver > 144) return;              // Older versions only.
  214.   if (!infilemenu) return;               // Only if we're in the
  215.   infilemenu = 0;                        // file menu.
  216.   if (pcb)
  217.   { cputs ("^M");                        // Send CR to terminate.
  218.     if (success)                         // Start transfer now?
  219.     { waitfor ("(A)bort?",10);
  220.       cputs ("^M");